//数据交互服务
app.service("serve",function ($http, $q, $rootScope) {
  this.get = function(urlStr) {
      var deferred = $q.defer();
      if($rootScope.token) {
        var reg = /\?/;
        if(reg.test(urlStr)) {
          urlStr = urlStr + "&&token=" + $rootScope.token;
        } else {
          urlStr = urlStr + "?token=" + $rootScope.token;
        }
      }
      $http.get(urlStr).  
          success(function(data, status, headers, config) { 
            deferred.resolve(data);   
          }).error(function(data, status, headers, config) {
            if (!!data.describe) {
              return $.toast(data.describe)
            }
            $.toast("出错了");
            deferred.reject(data);   
          });  
      return deferred.promise; 
  }
  this.post = function(url,data) {
      var deferred = $q.defer(); 
      $http.post(url,data)
        .success(function(data, status, headers, config) { 
          deferred.resolve(data);   
        }).error(function(data, status, headers, config) {
          if (!!data.describe) {
              return $.toast(data.describe)
          }
          $.toast("出错了");
          deferred.reject(data);   
        }); 
      return deferred.promise;
  }
})